package com.nbsaas.boot.article.rest.convert;

import com.nbsaas.boot.article.data.entity.Article;
import com.nbsaas.boot.article.api.domain.response.ArticleResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;

/**
 * -实体对象转化成响应对象
 */

public class ArticleResponseConvert implements Converter<ArticleResponse, Article> {

    @Override
    public ArticleResponse convert(Article source) {
        ArticleResponse result = new ArticleResponse();
        BeanDataUtils.copyProperties(source, result);
        if (source.getCatalog() != null) {
            result.setCatalog(source.getCatalog().getId());
        }
        if (source.getDocument() != null) {
            result.setDocument(source.getDocument().getId());
        }
        if (source.getCatalog() != null) {
            result.setCatalogName(source.getCatalog().getName());
        }
        if (source.getStoreState() != null) {
            result.setStoreStateName(String.valueOf(source.getStoreState()));
        }
        if (source.getUser() != null) {
            result.setUser(source.getUser().getId());
        }
        return result;
    }

}

